#include "StdAfx.h"
#include "LasHeader.h"

#include <Guiddef.h>


CLasHeader::CLasHeader(void)
{

}

CLasHeader::~CLasHeader(void)
{
}

void CLasHeader::ReadHeader(const void *pBuf)
{
	const unsigned char *pCurrent = (unsigned char *)pBuf;
	memcpy_s(m_sFileSignature, 4, pCurrent, 4);
	pCurrent += 4;
	m_uiReserved = *(unsigned long *)pCurrent;
	pCurrent += sizeof(m_uiReserved);
	memcpy_s(&m_GUIDData, sizeof(m_GUIDData), pCurrent, sizeof(m_GUIDData));
	pCurrent += sizeof(m_GUIDData);
	m_ubVersionMajor = *pCurrent;
	pCurrent += 1;
	m_ubVersionMinor = *pCurrent;
	pCurrent += 1;
	memcpy_s(m_sSystemIdentifier, 32, pCurrent, 32);
	pCurrent += 32;
	memcpy_s(m_sGenerationSoftware, 32, pCurrent, 32);
	pCurrent += 32;
	m_wFlightDataJulian = *(unsigned short *)pCurrent;
	pCurrent += sizeof(m_wFlightDataJulian);
	m_wYear = *(unsigned short *)pCurrent;
	pCurrent += sizeof(m_wYear);
	m_wHeaderSize = *(unsigned short *)pCurrent;
	pCurrent += sizeof(m_wHeaderSize);
	m_uiOffsetToData = *(unsigned long *)pCurrent;
	pCurrent += sizeof(m_uiOffsetToData);
	m_uiNumberOfVariableLengthRecords = *(unsigned long *)pCurrent;
	pCurrent += sizeof(m_uiNumberOfVariableLengthRecords);
	m_ubPointDataFormatID = *(unsigned char*)pCurrent;
	pCurrent += sizeof(m_ubPointDataFormatID);
	m_wPointDataRecordLength = *(unsigned short *)pCurrent;
	pCurrent += sizeof(m_wPointDataRecordLength);
	m_uiNumberOfPointRecords = *(unsigned long *)pCurrent;
	pCurrent += sizeof(m_uiNumberOfPointRecords);
	memcpy_s(m_uiNumberOfPointsByReturn, 20, pCurrent, 20);
	pCurrent += 20;
	m_dXScaleFactor = *(double *)pCurrent;
	pCurrent += sizeof(m_dXScaleFactor);
	m_dYScaleFactor = *(double *)pCurrent;
	pCurrent += sizeof(m_dYScaleFactor);
	m_dZScaleFactor = *(double *)pCurrent;
	pCurrent += sizeof(m_dZScaleFactor);
	m_dXOffset = *(double *)pCurrent;
	pCurrent += sizeof(m_dXOffset);
	m_dYOffset = *(double *)pCurrent;
	pCurrent += sizeof(m_dYOffset);
	m_dZOffset = *(double *)pCurrent;
	pCurrent += sizeof(m_dZOffset);
	m_dMaxX = *(double *)pCurrent;
	pCurrent += sizeof(m_dMaxX);
	m_dMinX = *(double *)pCurrent;
	pCurrent += sizeof(m_dMinX);
	m_dMaxY = *(double *)pCurrent;
	pCurrent += sizeof(m_dMaxY);
	m_dMinY = *(double *)pCurrent;
	pCurrent += sizeof(m_dMinY);
	m_dMaxZ = *(double *)pCurrent;
	pCurrent += sizeof(m_dMaxZ);
	m_dMinZ = *(double *)pCurrent;
	pCurrent += sizeof(m_dMinZ);
}

int CLasHeader::GetDataOffset() const
{
	return m_uiOffsetToData;
}

int CLasHeader::GetPointType() const
{
	return m_ubPointDataFormatID;
}

int CLasHeader::GetPointRecordLength() const
{
	return m_wPointDataRecordLength;
}

int CLasHeader::GetNumberOfPointRecords() const
{
	return m_uiNumberOfPointRecords;
}

double CLasHeader::GetXScaleFactor() const
{
	return m_dXScaleFactor;
}

double CLasHeader::GetYScaleFactor() const
{
	return m_dYScaleFactor;
}

double CLasHeader::GetZScaleFactor() const
{
	return m_dZScaleFactor;
}

double CLasHeader::GetXOffset() const
{
	return m_dXOffset;
}

double CLasHeader::GetYOffset() const
{
	return m_dYOffset;
}

double CLasHeader::GetZOffset() const
{
	return m_dZOffset;
}

